// ****************************************************************
//   Rock.java
//
//   Play Rock, Paper, Scissors with the user
//   moodle should have other licenses      
// ****************************************************************
import java.util.Scanner;
import java.util.Random;

public class Rock{
    public static void main(String[] args){
	
	String personPlay = "this program failed if you see this";    //User's play -- "R", "P", or "S"
	String computerPlay = "this program failed if you see this";  //Computer's play -- "R", "P", or "S"
	int computerInt;      //Randomly generated number used to determine
	int computerScore = 0;
	int personScore = 0;
	String play = "y";                      //computer's play

      Scanner scan = new Scanner(System.in);
	Random generator = new Random();

while ((play.equals("y") || play.equals("Y"))) {
	personPlay = "this program failed if you see this";
	computerPlay = "this program failed if you see this";
	System.out.println("Please enter R, P or S. (Rock, Paper, Scissors)");
	//Get player's play -- note that this is stored as a string
	while(!personPlay.equals("R") && !personPlay.equals("P") && !personPlay.equals("S")){
		personPlay = scan.next();
		//Make player's play upper case for ease of comparison
		personPlay = personPlay.toUpperCase();
		if(!personPlay.equals("R") && !personPlay.equals("P") && !personPlay.equals("S")){
		System.out.println("That is not a valid response, please try again");
		}
		}
	//Generate computer's play (0,1,2)
	computerInt = generator.nextInt(3);
	//Translate computer's randomly generated play to string
	switch (computerInt){
		case 0: computerPlay = "R"; break;
		case 1: computerPlay = "P"; break;
		case 2: computerPlay = "S"; break;
	}

	//Print computer's play
	//See who won.  Use nested if s instead of &&. This is evil to my brain.
	if (personPlay.equals(computerPlay))
	    {
		System.out.println("It's a tie!");
		}
		
	else if (personPlay.equals("R"))
		{
		if (computerPlay.equals("P"))
		{
			System.out.println("You Lose");
			computerScore++;
		}
		else
		{
			System.out.println("You Win");
			personScore++;
		}
		
		}
	else if (personPlay.equals("P"))
		{
		if (computerPlay.equals("R"))
		{
			System.out.println("You Win");
			personScore++;
		}
		else
		{
			System.out.println("You Lose");
			computerScore++;
		}
		}
	else if (personPlay.equals("S"))
		{
		if (computerPlay.equals("R"))
		{
			System.out.println("You Lose");
			computerScore++;
		}
		else
		{
			System.out.println("You Win");
			personScore++;
		}
		}
	System.out.println("Your score:" + personScore);
	System.out.println("Computer score:" + computerScore);
	System.out.println("Do you want to play again? (y/n)");
	play = scan.next();

	}
	scan.close();
	System.out.println("THANKS FOR PLAYING THIS PATHETIC GAME");
    }
}